package com.study.test.demo.observer;

import java.util.Observable;
import java.util.Observer;

/**
 * jdk里的观察者模式。观察者继承Observer
 *
 * @Author hupengming
 * @ClassName Teacher
 * @Date 2023-03-14  11:37
 * @Version 1.0
 */
public class Teacher implements Observer {

    private String name;

    public Teacher(String name) {
        this.name = name;
    }

    @Override
    public void update(Observable o, Object arg) {
        if (o instanceof GPer) {
            GPer gPer = (GPer) o;
            if (arg instanceof Question) {
                Question question = (Question) arg;
                System.out.println("=========================");
                System.out.println(this.name + "老师！您好，你收到" + gPer.getName() + "消息 \n"
                        + "消息内容：" + question.getContent() + "\n发送者：" + question.getUser());
            }
        }
    }
}
